package com.moons.view;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Handler;
import android.text.method.ScrollingMovementMethod;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateInterpolator;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import java.lang.ref.WeakReference;

import com.moons.settings.R;

public class ToolsDialog {

    private PopupWindow popupWindow;
    private View layout;

    private LinearLayout tool_password;
    private LinearLayout tool_quit;

    private WeakReference<Activity> activityWeakReference;

    public ToolsDialog(final Activity context){
        activityWeakReference = new WeakReference<>(context);

        LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        layout = layoutInflater.inflate(R.layout.layout_tools_dialog, null);

        popupWindow = new PopupWindow(context);
        popupWindow.setContentView(layout);
        popupWindow.setWidth(400);
        popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        popupWindow.setFocusable(true);
        popupWindow.setBackgroundDrawable(new ColorDrawable(/*context.getResources().getColor(R.color.color_Tool_Background)*/android.graphics.Color.TRANSPARENT));

        final View decor=popupWindow.getContentView();
        decor.setOnSystemUiVisibilityChangeListener (new View.OnSystemUiVisibilityChangeListener() {
            public void onSystemUiVisibilityChange(int visibility) {
                android.util.Log.d("d", "onSystemUiVisibilityChange");
                new Handler().postDelayed(new Runnable() {
                    public void run(){
                        decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE
                                // Hide the nav bar and status bar
                                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                                | View.SYSTEM_UI_FLAG_FULLSCREEN);
                    }
                }, 500);
            }
        });
    }

    public void show(){
        popupWindow.showAtLocation(layout,Gravity.BOTTOM,0,300);
    }

    public void close(){
        if(popupWindow.isShowing()) {
            popupWindow.dismiss();
        }
    }

}
